var KK = window.KK = {
	_ucurl:'http://passport.chuanke.com',
	_kkurl:'http://www.chuanke.com',
	_resurl:'http://res.ckimg.com',
	_answerUrl : 'http://wenda.chuanke.com',
	_kkdownload:'http://download.chuanke.com/client/KK.exe',
	_kkipad:'http://kk.chuanke.com/ipad',
	_kkiphone:'http://kk.chuanke.com/iphone',
	_kkandroid:'http://kk.chuanke.com/android',
	_uploadImgUrl : 'http://upload.img.chuanke.com',
	_uploadCourseware : 'http://web.v.chuanke.com/video.upload',
	//站点名称:index,uc,bbs
	_site:'index',
	_isHome:false,
	//第三方登录
	_sinaLogin:"http://passport.chuanke.com/login/auth?from=sina",
	_qqLogin:"http://passport.chuanke.com/login/auth?from=qq",
	_rrLogin:"http://passport.chuanke.com/login/auth?from=renren",
	_baiduLogin:"http://passport.chuanke.com/login/auth?from=baidu",
	//配置项
	_config:{
		broadCast : '',
		adminMenu : ''
	},
	//学生广播项(我的课程)
	_studentBroadCast:{
		todayCurrCourse : 0,	//今日直播
        tomorrowOffLine : 0,    //明日线下课程
		handselCourse : 0,		//课程授权
		schoolComment : 0		//学校评价学生数
	},
	//老师广播项
	_teacherBroadCast:{
		schoolInvite : 0		//学校邀请加盟
	},
	//师长广播项
	_schoolBroadCast:{
		teacherApply	: 0,	//老师加盟申请
		refundApply		: 0,	//退款申请
		student1v1		: 0,	//新增1V1学生
		studentComment	: 0,	//学生评价课程数
		newOrderCnt		: 0		//新产生的订单数		
	},
	
	_messageItems : {
		courseMsgCnt:0,
		tradeMsgCnt:0,
		commentMsgCnt:0,
		systemMsgCnt:0,
        dynamicMsgCnt:0,
		totalMsgCnt:0
	},
	
	user:{
		userid:0,
		username:'',
		nickname:'',
		cart:0
	},
	
	_close_box : [],	//直播课课前提醒

	init : function(){
		var authinfo = this.readCookie("AuthInfo"),
		close_box_cookie = this.readCookie('alert_class_list');
		this._close_box = (close_box_cookie == '' || close_box_cookie == null) ? [] : close_box_cookie.split(',');
		
		if(typeof authinfo == "string"){
			try{
				var userinfo = eval('('+this.base64_decode(authinfo)+')'); 
				this.user.userid = userinfo.userid;
				this.user.username = userinfo.username;
				this.user.nickname = userinfo.nickname;
			}catch(e){}
		}
		var cartinfo = this.readCookie("CartInfo");
		if(typeof cartinfo == "string"){
			try{
				cart = eval('('+this.base64_decode(cartinfo)+')');
				this.user.cart = cart;
			}catch(e){}
		}
		
		if (this.checkLogin()) {
			//我的课程红点及老师、学生、校长后台首页广播
			this.checkBroadCast();
			
			//学习记录
			$("#topBar li.time").mouseover(function(){
				//alert('ddd');
			});			

			//购物车
			this.updateCartCount();
			//我的课程页面LEFT MENU
			if(KK._config.adminMenu == 'student'){
				this.buildStudentMenu();
			}else if(KK._config.adminMenu == 'teacher'){
				this.buildTeacherMenu();
			}else if(KK._config.adminMenu == 'seller'){
				this.buildSellerMenu();
			}


			var reg = /v(\d+)\-(\d+)\-(\d+)\.html$/;
			var url_str = window.location.pathname;
			var reg_result = reg.test(url_str);
			if (reg_result !== true) {
				this.liveClassAlert();
			}
		}
	},
	
	//直播课课前提醒
	liveClassAlert:function(){

		var Account;

		var slideAlert = function(cid, course_name, enter_link){
			if ($.inArray(cid, KK._close_box) < 0) {
				var slideBox = ['<div class="zb-tips-box" cid="'+cid+'">',
					'<a class="btn-close" href="javascript:;"></a>',
					'<div class="con">'+course_name+'</div>',
					'<div class="tr pt10 mr10">',
					'<a class="link-into" target="_blank" href="'+enter_link+'">即将上课，进入教室></a></div></div>'].join("");
				if (typeof ($('.zb-tips-box[cid="' + cid + '"]').html()) != 'string') {
					$("#aside-tips").append(slideBox);
				}
			}
		};

		var CourseLiveHintTimer = function(CID, remainTimer) {
			var iHour, iMinute, iSecond, sHour, sMinute, sSecond, sTime;

			if (remainTimer > 0) {
				iHour = parseInt(((remainTimer / 3600)));
				if (iHour > 0) {
					sHour = iHour + ':';
				}else if(iHour <= 0) {
					sHour = '00:';
				}
				iMinute = parseInt((remainTimer / 60) % 60);
				if (iMinute > 0) {
					if (iMinute < 10) {
						sMinute = '0' + iMinute + ':';
					} else {
						sMinute = iMinute + ':';
					}
				} else if(iMinute <= 0) {
					sMinute = '00:';
				}
				iSecond = parseInt(remainTimer % 60);
				if (iSecond >= 0) {
					if (iSecond < 10) {
						sSecond = '0' + iSecond;
					} else {
						sSecond = iSecond;
					}
				}
				sTime = sHour + sMinute + sSecond;
				if (remainTimer <= 0) {
					clearTimeout(Account);
				} else {
					Account = setTimeout(function(){CourseLiveHintTimer(CID, remainTimer);}, 1000);
				}
			} else {
				var live_start = '#dialog-live-time-' + CID;
				$(live_start).empty();
				$(live_start).html('<p class="dialog-live-title">直播已开始</p>');
				return;
			}
            remainTimer = remainTimer - 1;
            var live_process = '#course-live-remain-timer-' + CID;
            $(live_process).text(sTime);
		};

		var showNextBox = function() {
			$('.fe_dialogBox_live_new').eq(0).show();
		};

		var minuteAlert = function(key, item) {
			var enter_link  = KK._kkurl+'/'+item.SID+'/'+item.CourseID+'/'+item.CID+'.html';
			var remainTimer = item.Timer; //按秒计算
			var display = (key == 0) ? 'display:block;' : 'display:none';
			var slideBox = ['<div id="dialog-live-box-'+ item.CID +'" class="fe_dialogBox fe_dialogBox_live_new png_bg" style="width: 309px;height: 198px;margin: -111px 0 0 -309px;left: 100%; top: 260px;' + display + '"><div class="fe_dialog" style="width: 300px;height: 186px;margin: 5px;"><div class="contains"><div class="hd">直播提醒</div><div class="bd dialog-live"><div class="dialog-con"><p class="title"><a target="_blank"  cid="'+  item.CID + '" class="enter_live_link" href="' + enter_link + '">' + item.CourseName +'</a></p><div class="dialog-live-con clearfix"><a target="_blank"  cid="'+  item.CID + '" class="enter_live_link" href="' + enter_link + '"><img class="fl" src="' + item.PhotoURL + '" alt=""></a><div class="dialog-live-btnair fr"><div id="dialog-live-time-'+ item.CID +'"><p class="dialog-live-time"><span>直播倒计时</span><span class="dialog-live-time-num" id="course-live-remain-timer-' + item.CID + '"></span></p></div><a target="_blank" cid="'+  item.CID + '" class="dialog-live-btn enter_live_link" href="'+ enter_link +'">进入教室</a></div></div></div></div></div><a href="javascript:;" class="close enter_live_link" cid="'+  item.CID + '">关闭</a></div></div>'].join('');
			$("#aside-tips").append(slideBox);
			CourseLiveHintTimer(item.CID, remainTimer);
		};

		$.ajax({
			url  : this._kkurl+"/?mod=cue&act=alert&do=course",
			type : "get",
			dataType : "jsonp",
			jsonp : "jsonpcallback",
			timeout : 3000,
			success : function(rs) {
				if (rs.code > 0){
					var show = 0;
					for(var key in rs.data){
						var item = rs.data[key];
						if ($.inArray(item.CID, KK._close_box) == -1) {
							minuteAlert(show, item);
							show++;
						}
					}
					$('.enter_live_link').click(function() {
						var cid = $(this).attr('cid');
						var box = '#dialog-live-box-' + cid;
						box = $(box);
						KK._close_box.push(cid);
						KK.setCookie('alert_class_list', KK._close_box.join(','), 60*60*1000);
						box.slideUp(500, function(){$(this).remove()});
						setTimeout(function(){showNextBox(cid)}, 1000);
					});
				}
			}
		});
	},

	updateCartCount:function() {
		$.ajax({
			url:this._kkurl+"/?mod=cart&act=operate&do=count&uid="+KK.user.userid+"&r="+Math.random(),
			type:"get",
			async:false,
			dataType:"script",
			success:function(){
				if(CartCnt > 0){
					$("#cartCount").text(CartCnt);
				}else{
					$("#cartCount").text(0);
				}
			}
		});
	},

	checkLogin:function() {
		if (this.user.userid > 0) {
			return true;
		} else {
			return false;
		}
	},
	
	buildHeaderBar:function() {
		$.ajax({
			url : this._kkurl + "/?mod=common&act=data&do=getHeaderBar&_r=" + Math.random(),
			type : "get",
			dataType : "jsonp",
			jsonp : "jsonpcallback",
			timeout : 3000,
			success : function(rs) {
				str = '<ul class="topR_nav">';
				//我的课程
				str += '<li class="myCourse">';
				if(parseInt(KK._studentBroadCast.todayCurrCourse) > 0 || parseInt(KK._studentBroadCast.handselCourse) > 0){
					str += '<a href="'+rs.MyCourse.url+'">'+rs.MyCourse.title+'<i class="icoR icoR_9"></i></a>';
				}else{
					str += '<a href="'+rs.MyCourse.url+'">'+rs.MyCourse.title+'</a>';
				}
				str += '<div class="hasChild">';
				str += '<ul class="ulNav">';
				$.each(rs.MyCourse.list, function(i, v){
					if(v.url.indexOf('timelist') > 0 && parseInt(KK._studentBroadCast.todayCurrCourse) > 0){
						str += '<li><a href="'+v.url+'" target="'+v.target+'">'+v.title+'<span class="tips-num">'+KK._studentBroadCast.todayCurrCourse+'<i class="angle"></i></span></a></li>';
					}else{
						str += '<li><a href="'+v.url+'" target="'+v.target+'">'+v.title+'</a></li>';
					}
				});
				str += '</ul>';
				str += '</div>';
				str += '</li>';

				//我是校长
				str += '<li class="seller curr">';
				str += '<a href="'+rs.Monitor.url+'">'+rs.Monitor.title+'</a>';
				str += '<div class="hasChild">';
				str += '<ul class="ulNav">';
				$.each(rs.Monitor.list, function(i, v){
					str += '<li><a href="'+v.url+'" target="'+v.target+'">'+v.title+'</a></li>';
				});
				str += '</ul>';
				str += '</div>';
				str += '</li>';

				//我是老师
				str += '<li class="teacher">';
				str += '<a href="'+rs.Teacher.url+'">'+rs.Teacher.title+'</a>';
				str += '<div class="hasChild">';
				str += '<ul class="ulNav">';
				$.each(rs.Teacher.list, function(i, v){
					str += '<li><a href="'+v.url+'" target="'+v.target+'">'+v.title+'</a></li>';
				});
				str += '</ul>';
				str += '</div>';
				str += '</li>';
				str += '</ul>';

				str += '<ul class="topR_user">';
				//消息
				str += '<li class="msg">';
				str += '<a href="'+rs.Message.url+'"><i class="icoR icoR_7"></i></a>';
				str += '<div class="hasChild">';
				str += '<ul class="msgSubList">';
				$.each(rs.Message.list, function(i, v){
					str += '<li class="'+v.liclass+'"><a href="'+v.url+'" target="'+v.target+'">'+v.title+'</a><i class="num '+v.icon+'">0</i></li>';
				});
				str += '<li class="clrTips">';
				str += '<span class="fr pt5 mr10"><a href="javascript:;" onclick="KK.clearMsgReminder()" class="n_btn24g">清除提醒</a></span>';
				str += '<a class="ml10" href="'+rs.Message.more.url+'">'+rs.Message.more.title+'</a>';
				str += '</li>';
				str += '</ul>';
				str += '</div>';
				str += '</li>';

				//头像
				str += '<li class="photo">';
				str += '<a href="'+rs.Avatar.link+'"><img src="'+rs.Avatar.url+'" width="40" height="40" alt=""></a>';
				str += '<div class="hasChild">';
				str += '<ul class="ulUser">';
				$.each(rs.Avatar.list, function(i, v){
					str += '<li class="'+v.liclass+'"><a href="'+v.url+'" target="'+v.target+'">'+v.title+'</a></li>';
				});
				str += '</ul>';
				str += '</div>';
				str += '</li>';
				str += '</ul>';
	
				$("#head_searchKeywords").css("width", "173px");
				$("#header_bar").html(str);

				//消息通知
				KK.checkMessage();
			}
		});
	},
	
	checkMessage : function(){
		$.ajax({
			url : this._kkurl+"/?mod=message&_r="+Math.random(),
			type : "get",
			dataType : "jsonp",
			jsonp : "jsonpcallback",
			timeout : 5000,
			success : function(rs){
				KK._messageItems.courseMsgCnt = rs.courseMsgCnt;
				KK._messageItems.tradeMsgCnt = rs.tradeMsgCnt;
				KK._messageItems.commentMsgCnt = rs.commentMsgCnt;
				KK._messageItems.systemMsgCnt = rs.systemMsgCnt;
				KK._messageItems.dynamicMsgCnt = rs.dynamicMsgCnt;
				KK._messageItems.totalMsgCnt = rs.totalMsgCnt;
				if(KK._messageItems.totalMsgCnt > 0){
					$("#topBar li.msg").find("i.icoR").after('<i class="icoR icoR_10">'+KK._messageItems.totalMsgCnt+'</i>');
					$("#topBar ul.msgSubList").find("i.msg_course").text(KK._messageItems.courseMsgCnt).after(rs.courseItem);
					$("#topBar ul.msgSubList").find("i.msg_trade").text(KK._messageItems.tradeMsgCnt).after(rs.tradeItem);
					$("#topBar ul.msgSubList").find("i.msg_comment").text(KK._messageItems.commentMsgCnt).after(rs.commentItem);
					$("#topBar ul.msgSubList").find("i.msg_system").text(KK._messageItems.systemMsgCnt).after(rs.systemItem);
                    $("#topBar ul.msgSubList").find("i.msg_dynamic").text(KK._messageItems.dynamicMsgCnt).after('');
				}
			}
		});
	},
	
	clearMsgReminder : function(){
		$.ajax({
			url : this._kkurl+"/?mod=message&do=clearMsgReminder&_r="+Math.random(),
			type : "get",
			dataType : "jsonp",
			jsonp : "jsonpcallback",
			timeout : 5000,
			success : function(rs){
				if(rs.code > 0){
					KK._messageItems.courseMsgCnt = 0;
					KK._messageItems.tradeMsgCnt = 0;
					KK._messageItems.commentMsgCnt = 0;
					KK._messageItems.systemMsgCnt = 0;
					KK._messageItems.dynamicMsgCnt = 0;
					KK._messageItems.totalMsgCnt = 0;
					$("#topBar li.msg").find("i.icoR").next("i.icoR_10").remove();
					$("#topBar ul.msgSubList").find("i.msg_course").text(KK._messageItems.courseMsgCnt).next("ul").remove();
					$("#topBar ul.msgSubList").find("i.msg_trade").text(KK._messageItems.tradeMsgCnt).next("ul").remove();
					$("#topBar ul.msgSubList").find("i.msg_comment").text(KK._messageItems.commentMsgCnt).next("ul").remove();
					$("#topBar ul.msgSubList").find("i.msg_system").text(KK._messageItems.systemMsgCnt).next("ul").remove();
                    $("#topBar ul.msgSubList").find("i.msg_dynamic").text(KK._messageItems.dynamicMsgCnt).next("ul").remove();
				}
			}
		});
		return false;
	},
	
	checkBroadCast:function(){
		jQuery.support.cors = true;
		//if(KK._config.broadCast == 'studentIndex'){
			$.ajax({
				url : this._kkurl+"/?mod=common&act=data&do=getStudentBroadCast&_r="+Math.random(),
				type : "get",
				dataType : "jsonp",
				jsonp : "jsonpcallback",
				timeout: 5000,
				async : false,
				success : function(rs){ 
					KK._studentBroadCast.todayCurrCourse = rs.todayCurrCourse;
					KK._studentBroadCast.handselCourse = rs.handselCourse;
					KK._studentBroadCast.schoolComment = rs.schoolComment;
					'tomorrowOffLine' in rs == true ? KK._studentBroadCast.tomorrowOffLine = rs.tomorrowOffLine : '';

					var url=String(window.document.location.href);
					var allargs = url.split("?")[1]; 
					if(allargs == 'mod=student&act=index'){
						KK.buildBroadCast();
					}
					KK.buildHeaderBar();
				}
			});
		//}else if(KK._config.broadCast == 'teacherIndex'){
		if(KK._config.broadCast == 'teacherIndex'){
			$.ajax({
				url : this._kkurl+"/?mod=common&act=data&do=getTeacherBroadCast&_r="+Math.random(),
				type : "get",
				dataType : "jsonp",
				jsonp : "jsonpcallback",
				timeout: 5000,
				success : function(rs){
					KK._teacherBroadCast.schoolInvite = rs.schoolInvite;
					KK.buildBroadCast();
				}
			});
		}else if(KK._config.broadCast == 'sellerIndex'){
			$.ajax({
				url : this._kkurl+"/?mod=common&act=data&do=getSellerBroadCast&_r="+Math.random(),
				type : "get",
				dataType : "jsonp",
				jsonp : "jsonpcallback",
				timeout: 5000,
				success : function(rs){
					KK._schoolBroadCast.teacherApply = rs.teacherApply;
					KK._schoolBroadCast.refundApply = rs.refundApply;
					KK._schoolBroadCast.student1v1 = rs.student1v1;
					KK._schoolBroadCast.studentComment = rs.studentComment;
					KK._schoolBroadCast.newOrderCnt = rs.newOrderCnt;
					KK.buildBroadCast();
				}
			});
		}
	},
	
	buildBroadCast:function(){

		if(KK._config.broadCast == 'studentIndex'){
			if(parseInt(KK._studentBroadCast.todayCurrCourse) > 0 || parseInt(KK._studentBroadCast.tomorrowOffLine) > 0 || parseInt(KK._studentBroadCast.handselCourse) > 0 || parseInt(KK._studentBroadCast.schoolComment) > 0){
                 
				var htmlArray = ['<section class="myck_item1 broadCast" style="display:none">','<div class="message_box">'];
				var isMulti = false;
                
				if(parseInt(KK._studentBroadCast.todayCurrCourse) > 0){
					htmlArray.push('<a href="'+this._kkurl+'/?mod=student&act=course&do=timelist"><span class="f14"><i class="c_f60">'+KK._studentBroadCast.todayCurrCourse+'</i>节今日直播课</span></a>');
					isMulti = true;
				}
				 
				if(parseInt(KK._studentBroadCast.tomorrowOffLine) > 0){
					isMulti == true && htmlArray.push('<i class="ml20 mr20 c_ccc">|</i>');
					htmlArray.push('<a href="'+this._kkurl+'/?mod=student&act=course"><span class="f14"><i class="c_f60">'+KK._studentBroadCast.tomorrowOffLine+'</i>节线下课程明天上课！</span></a>');
					isMulti = true;
				}

				if(parseInt(KK._studentBroadCast.handselCourse) > 0){
					isMulti == true && htmlArray.push('<i class="ml20 mr20 c_ccc">|</i>');
					htmlArray.push('<a href="'+this._kkurl+'/?mod=student&act=course&do=authorize"><span class="f14"><i class="c_f60">'+KK._studentBroadCast.handselCourse+'</i>个课程赠送</span></a>');
					isMulti = true;
				}

				if(parseInt(KK._studentBroadCast.schoolComment) > 0){
					isMulti == true && htmlArray.push('<i class="ml20 mr20 c_ccc">|</i>');
					htmlArray.push('<a href="'+this._kkurl+'/?mod=student&act=credit&comment=1"><span class="f14"><i class="c_f60">'+KK._studentBroadCast.schoolComment+'</i>个学校评价</span></a>');
				}
					
				htmlArray.push('</div></section>');         
				var html = htmlArray.join('');

			}
		}else if(KK._config.broadCast == 'teacherIndex'){
			if(parseInt(KK._teacherBroadCast.schoolInvite) > 0){
				var html = ['<section class="myck_item1 broadCast mb20" style="display:none">',
							'<div class="message_box">',
							'<a href="'+this._kkurl+'/?mod=teacher&act=school&type=0"><span class="f14"><i class="c_f60">'+KK._teacherBroadCast.schoolInvite+'</i>个加盟邀请</span></a>',
							'</div></section>'].join('');
			}
		}else if(KK._config.broadCast == 'sellerIndex'){
			if(parseInt(KK._schoolBroadCast.teacherApply) > 0 || parseInt(KK._schoolBroadCast.refundApply) > 0 || parseInt(KK._schoolBroadCast.student1v1) > 0 || parseInt(KK._schoolBroadCast.studentComment) > 0 || parseInt(KK._schoolBroadCast.newOrderCnt) > 0){
				var html = ['<section class="myck_item1 broadCast mb20" style="display:none">',
							'<div class="message_box">',
							parseInt(KK._schoolBroadCast.teacherApply) > 0 ? '<a href="'+this._kkurl+'/?mod=seller&act=teacher&do=sign&type=1"><span class="f14"><i class="c_f60">'+KK._schoolBroadCast.teacherApply+'</i>个加盟申请</span></a>' : '',
							(parseInt(KK._schoolBroadCast.teacherApply) > 0 && parseInt(KK._schoolBroadCast.refundApply) > 0) ? '<i class="ml20 mr20 c_ccc">|</i>' : '',
							parseInt(KK._schoolBroadCast.refundApply) > 0 ? '<a href="'+this._kkurl+'/?mod=seller&act=refund&do=list&status=1"><span class="f14"><i class="c_f60">'+KK._schoolBroadCast.refundApply+'</i>个退款申请</span></a>' : '',
							((parseInt(KK._schoolBroadCast.teacherApply) > 0 || parseInt(KK._schoolBroadCast.refundApply) > 0 ) && parseInt(KK._schoolBroadCast.student1v1) > 0) ? '<i class="ml20 mr20 c_ccc">|</i>' : '',
							parseInt(KK._schoolBroadCast.student1v1) > 0 ? '<a href="'+this._kkurl+'/?mod=1v1&act=seller&do=deploy&status=1"><span class="f14"><i class="c_f60">'+KK._schoolBroadCast.student1v1+'</i>个1对1新增订单</span></a>' : '',
							((parseInt(KK._schoolBroadCast.teacherApply) > 0 || parseInt(KK._schoolBroadCast.refundApply) > 0 || parseInt(KK._schoolBroadCast.student1v1) > 0) && parseInt(KK._schoolBroadCast.studentComment) > 0) ? '<i class="ml20 mr20 c_ccc">|</i>' : '',
							parseInt(KK._schoolBroadCast.studentComment) > 0 ? '<a href="'+this._kkurl+'/?mod=seller&act=credit&comment=1"><span class="f14"><i class="c_f60">'+KK._schoolBroadCast.studentComment+'</i>个学生评价</span></a>' : '',
							((parseInt(KK._schoolBroadCast.teacherApply) > 0 || parseInt(KK._schoolBroadCast.refundApply) > 0 || parseInt(KK._schoolBroadCast.student1v1) > 0 || parseInt(KK._schoolBroadCast.studentComment) > 0) && parseInt(KK._schoolBroadCast.newOrderCnt) > 0) ? '<i class="ml20 mr20 c_ccc">|</i>' : '',
							parseInt(KK._schoolBroadCast.newOrderCnt) > 0 ? '<a href="'+this._kkurl+'/?mod=seller&act=order"><span class="f14"><i class="c_f60">'+KK._schoolBroadCast.newOrderCnt+'</i>个新增的销售定单</span></a>' : '',	
							'</div></section>'].join('');
			}
		}
		$("div.pageContent").prepend(html);
		$(".broadCast").slideDown();
	},
	
	buildStudentMenu:function(){
		$.getJSON(this._kkurl+"/?mod=common&act=data&do=getStudentMenu&_r="+Math.random(), function(rs){
			var data = rs.data;
			for(var i in data){
				if (parseInt(data[i]) > 0) {
					KK.replaceMenu("studentMenu", i, data[i]);
				}
			}
		});
	},
	
	buildTeacherMenu:function(){
		$.getJSON(this._kkurl+"/?mod=common&act=data&do=getTeacherMenu&_r="+Math.random(), function(rs){
			var data = rs.data;
			for(var i in data){
				if (parseInt(data[i]) > 0) {
					KK.replaceMenu("teacherMenu", i, data[i]);
				}
			}
		});
	},
	
	buildSellerMenu:function(){
		$.getJSON(this._kkurl+"/?mod=common&act=data&do=getSellerMenu&_r="+Math.random(), function(rs){
			var data = rs.data;
			for(var i in data){
				if (parseInt(data[i]) > 0) {
					KK.replaceMenu("sellerMenu", i, data[i]);
				}
			}
		});
	},

	/**
	 * 用于页面操作引起的MENU的数值变化，可直接使用本方法动态修改
	 * step值为"+","-"，表示增加和减少val的值， <span class="tips-num">99<i class="angle"></i></span>
	 */
	replaceMenu:function(nodeId, itemClass, val, step){
		if (val <= 0) {
			return;
		}
		var itemNode = $("#"+nodeId+" li."+itemClass).find('a'),
			itemText = itemNode.find('span.tips-num').text();
		if (itemNode.find('span.tips-num').length <= 0) {
			if (typeof step == 'undefined') {
				if(val > 99)	val = '99+';
				itemNode.append('<span class="tips-num">'+val+'<i class="angle"></i></span>');
			}else{
				if (step == "+") {
					if(val > 99)	val = '99+';
					itemNode.append('<span class="tips-num">'+val+'<i class="angle"></i></span>');
				}
			}
		}else{
			if (step == "+") {
				itemNode.find('span.tips-num').text(itemText.replace(/\d+/, function(args){
					if(parseInt(args)+1 > 99)	val = '99+';
					return val;
				}));
			}else{
				if(parseInt(itemText.match(/\d+/)) - val <= 0){
					itemNode.find('span.tips-num').remove();
				}else{
					itemNode.find('span.tips-num').text(itemText.replace(/\d+/, function(args){
						if(parseInt(args)-1 > 99)	val = '99+';
						return val;
					}));
				}
			}
		}
	},
	
	setCookie : function(name,value,time){ ; 
	    var exp = new Date(); 
	    exp.setTime(exp.getTime() + time);
	    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString() + ";path=/;domain=" + this._kkurl.substr(11); 
	},

	readCookie:function(name) {
		var cookie = '';
		var search = name + '=';
		if (document.cookie.length > 0) {
			var offset = document.cookie.indexOf(search);
			if (offset != -1) {
				offset += search.length;
				var end = document.cookie.indexOf(";", offset);
				if (end == -1) {
					end = document.cookie.length;
				}
				cookie = document.cookie.substring(offset, end);
			}
		}
		return decodeURIComponent(cookie);
	},
	
	base64_decode:function(input) {
		var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
		var output = "";
		var chr1, chr2, chr3 = "";
		var enc1, enc2, enc3, enc4 = "";
		var i = 0;
		if (input.length % 4 != 0) {
			return "";
		}
		var base64test = /[^A-Za-z0-9\+\/\=]/g;
		if (base64test.exec(input)) {
			return "";
		}
		do {
			enc1 = keyStr.indexOf(input.charAt(i++));
			enc2 = keyStr.indexOf(input.charAt(i++));
			enc3 = keyStr.indexOf(input.charAt(i++));
			enc4 = keyStr.indexOf(input.charAt(i++));
			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;
			output = output + String.fromCharCode(chr1);
			if (enc3 != 64) {
				output+=String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output+=String.fromCharCode(chr3);
			}
			chr1 = chr2 = chr3 = "";
			enc1 = enc2 = enc3 = enc4 = "";
		} while (i < input.length);
		return output;
	},

	base64_encode:function(str) {
		var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
		var out, i, len;
		var c1, c2, c3;

		len = str.length;
		i = 0;
		out = "";
		while(i < len) {
			c1 = str.charCodeAt(i++) & 0xff;
			if(i == len) {
				out += base64EncodeChars.charAt(c1 >> 2);
				out += base64EncodeChars.charAt((c1 & 0x3) << 4);
				out += "==";
				break;
			}
			c2 = str.charCodeAt(i++);
			if(i == len) {
				out += base64EncodeChars.charAt(c1 >> 2);
				out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
				out += base64EncodeChars.charAt((c2 & 0xF) << 2);
				out += "=";
				break;
			}
			c3 = str.charCodeAt(i++);
			out += base64EncodeChars.charAt(c1 >> 2);
			out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
			out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6));
			out += base64EncodeChars.charAt(c3 & 0x3F);
		}
		return out;
	}
};

(function($, KK){
	$(function(){
		KK.init();
		setInterval("getrsp()",600000);
	})
})(jQuery, KK);

var _hmt = _hmt || [];
(function() {
   var hm = document.createElement("script");
   hm.src = "//hm.baidu.com/hm.js?2be0d6083ea4207036d33a4d8be519db";
   var s = document.getElementsByTagName("script")[0]; 
       s.parentNode.insertBefore(hm, s);
})();
